package com.lsc.admin.demo.thread;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.lsc.admin.demo.api.UserService;
import com.lsc.admin.demo.entity.User;
import com.smf.lsc.global.id.GlobalId;
 
@Service
public class AsyncTaskService {
	
	@Autowired
    private GlobalId globalId;
	
	@Autowired
	private UserService userService;
	
    @Async
    public void executeAsyncTask(int i) {
//    	for (int j = 0; j < 10000; j++) {
	    	long s1=globalId.getId("test");
	    	// 3、新增用户信息
			User user = new User();

			// 不设置id的话，会自动生成一个UUID
			long newUserId = globalId.getId("user-id");
			user.setId(String.valueOf(newUserId));

			user.setUserName("测试mysql大结果集查询"+String.valueOf(newUserId));

			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");// 设置日期格式
			user.setUserPassword(sdf.format(new Date()));
			boolean save = userService.save(user);

	    	System.out.println("线程" + Thread.currentThread().getName() + " 执行异步任务：" + i+" 序列："+s1);
//    	}
    }
}